package com.hxz.lesson03;

import com.hxz.lesson02.utils.JdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class TestSelect {
    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement st = null;
        ResultSet rs = null;

        try {
            conn = JdbcUtils.getConnection();

            //区别，使用？占位符代替参数
            String sql = "select * from users where id=?";
            st = conn.prepareStatement(sql); // 预编译sql，先写sql，不执行

            // 手动给参数赋值
            st.setInt(1,1);

            // 执行
            rs = st.executeQuery();
            while (rs.next()) {
                System.out.println("NAME="+rs.getObject("NAME"));
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            JdbcUtils.release(conn, st, rs);
        }
    }
}
